/**
 * 
 */
var Release = function() {
	var wait = '';
	return {
		exeData : function(url) {
			var timeOut = 0;
			wait = setInterval(function() {
				var code = $(".code").val();
				var returnCode = $(".return-code").val();
				if(returnCode != 0 || returnCode ==null){
					return;
				}
				$.ajax({
					type : "post",
					url : url,
					data : {
						"scode" : code
					},
					dataType : "json",
					async : true,
					success : function(data) {
                        if (data.returnCode == 0) {
                        	clearInterval(wait);
                        	location.href=data.data;
                        } else if (data.returnCode == 404) {
                        	clearInterval(wait);
        					$(".time_out").css("display","block");
    						$(".time_out>p").html("请求错误");
                        } else if (data.returnCode == 500) {
                        	clearInterval(wait);
        					$(".time_out").css("display","block");
        					$(".time_out>p").html("二维码已过期,请刷新");
                        } else if (data.returnCode == 200) {
                            $(".time_out").css("display","block");
                            $(".time_out").removeAttr("onclick");
                            $(".pswbt").removeAttr("onclick");
    						$(".time_out>p").html("设备已扫描,请在手机上授权");
                        } else if (data.returnCode == 201) {
        					$(".time_out").css("display","block");
                            $(".time_out").removeAttr("onclick");
                            $(".pswbt").removeAttr("onclick");
                        	clearInterval(wait);
    						$(".time_out>p").html("用户已取消授权");
                        } else if (data.returnCode == 204) {
                        	clearInterval(wait);
        					$(".time_out").css("display","block");
    						$(".time_out>p").html(data.returnMessage);
                        }else if (data.returnCode == 1000) {
                        	clearInterval(wait);
        					$(".time_out").css("display","block");
    						$(".time_out>p").html(data.returnMessage);
                        }
					},
					error : function() {
                    	clearInterval(wait);
					}
				});
				if(timeOut == 120){
					clearInterval(wait);
					$(".time_out>p").html("二维码已过期,请刷新");
					$(".time_out").css("display","block");
				}
				timeOut += 1;
			}, 1000);
		},
		change : function(type,changeType,url){
			if("qrcode_background" == changeType){
				location.href= url ;
			}else{
				clearInterval(wait);
				$(".time_out").css("display","block");
				$(".time_out").removeAttr("onclick");
				$(".time_out>p").html("二维码，加载中...");
			}
			$("."+type).css("display","none");
			$("."+changeType).css("display","block");
			$(".error").html("");
		},
		refresh : function(url){
			location.href= url ;
		}
	};

}();